package com.tedu.jdbc;

import com.tedu.utils.JDBCUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 *
 * @author zq
 * @version 1.0
 * @create 2024-07-30 14:09
 * @since jdk1.8
 */
public class JDBCDemo02 {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs=null;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名");
        String username = sc.nextLine();
        System.out.println("请输入新密码");
        String pwd = sc.nextLine();
        try {
            conn = JDBCUtils.getConnection();
            Statement statement = conn.createStatement();
            String sql = "update userinfo set password='" + pwd + "'where username='" + username + "'";
            int i = statement.executeUpdate(sql);
            if (i > 0) {
                System.out.println("修改成功");
            } else {
                System.out.println("修改失败");
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            JDBCUtils.close(rs, ps, conn);
        }
    }
}
